/**
 * @description 路由封装
 */

import { lazy } from 'react';

// 获取所有路由文件
const files = (require as any).context('../modules', true, /\.route\.(t|j)s$/);

let configRouters: Record<string, any>[] = [];

files.keys().forEach((key: string): void => {
  configRouters = configRouters.concat(files(key).default);
});

// 展平路由
const flattenRoutes: any[] = configRouters.map((x) => x.routes).flat();

const BasicLayout = lazy(() => import('@/pages/BasicLayout'));

export const routes = [
  {
    path: '/login',
    Component: lazy(() => import('@/pages/Login')),
  },
  {
    path: '/',
    Component: BasicLayout,
    children: [...flattenRoutes],
  },
];

export default routes;
